/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import view.additional.CellItem;
import view.additional.ThumbList;
import view.additional.TickerRenderer;
/**
 *
 * @author Kvest
 */
public class ExitMenu extends Form implements ActionListener
{
    public static final int OK_ID = 1;
    public static final int BACK_ID = 2;
    public static final int EXIT_PAUSE_ID = 3;
    public static final int EXIT_CLOSE_RELAY_ID = 4;
    public static final int EXIT_TEMPORARILY_ID = 5;

    private Command ok;
    private Command back;
    private FormAction listener;

    private ThumbList items;

    public ExitMenu(FormAction listener)
    {
        super("Выход");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());
        setScrollable(false);

        addCommandListener(this);

        back= new Command("Назад", BACK_ID);
        addCommand(back);

        ok = new Command("Ok", OK_ID);
        addCommand(ok);

        //Создаем и настраиваем список
        items = new ThumbList();
        items.setSelectCommandText("");
        items.setFixedSelection(ThumbList.FIXED_NONE_CYCLIC);
        TickerRenderer render = new TickerRenderer();
        render.getStyle().setPadding(Component.BOTTOM, 0);
        render.getStyle().setPadding(Component.TOP, 0);
        items.setRenderer(render);
        items.getStyle().setPadding(Component.BOTTOM, 0);
        items.getStyle().setPadding(Component.TOP, 0);

        items.addItem(new CellItem(EXIT_PAUSE_ID, "Уйти на перерыв"));
        items.addItem(new CellItem(EXIT_CLOSE_RELAY_ID, "Закрыть смену"));
        items.addItem(new CellItem(EXIT_TEMPORARILY_ID, "Временно выйти"));

        addComponent(BorderLayout.CENTER,items);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            Command cmd = evt.getCommand();
            if (cmd.getId() == OK_ID)
            {
                CellItem item = (CellItem)items.getSelectedItem();
                if (item != null)
                {
                    listener.commandAction(item.getId());
                }
            }
            else
            {
                listener.commandAction(cmd.getId());
            }
        }
    }
}
